package com.jf3q.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.jf3q.admin.service.EduCourseDescriptionService;
import com.jf3q.admin.service.EduCourseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jf3q.common.domain.EduChapter;
import com.jf3q.common.domain.EduCourse;

import com.jf3q.common.domain.EduCourseDescription;
import com.jf3q.common.domain.EduVideo;
import com.jf3q.common.exception.JfException;
import com.jf3q.common.mapper.EduChapterMapper;
import com.jf3q.common.mapper.EduCourseMapper;
import com.jf3q.common.mapper.EduVideoMapper;
import com.jf3q.common.vo.CourseInfoVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class EduCourseServiceImpl extends ServiceImpl<EduCourseMapper, EduCourse>
    implements EduCourseService {
    //课程描述注入
    @Autowired
    private EduCourseDescriptionService courseDescriptionService;
    @Autowired
    EduChapterMapper chapterMapper;

    @Autowired
    EduVideoMapper videoMapper;





    @Override
    public void del(String id) {
        LambdaQueryWrapper<EduChapter> chapterQueryWrapper= new LambdaQueryWrapper();
        Long chapterNum = chapterMapper.selectCount(chapterQueryWrapper.eq(EduChapter::getCourseId, id));
        if (chapterNum>0){

            throw new JfException(50000,"该课程下有章节，删除失败!");
        }
        LambdaQueryWrapper<EduVideo> videoQueryWrapper= new LambdaQueryWrapper();
        Long videoNum = videoMapper.selectCount(videoQueryWrapper.eq(EduVideo::getCourseId, id));

        if (videoNum>0){
            throw new JfException(50000,"该课程下有小节，删除失败!");
        }

        this.removeById(id);
        courseDescriptionService.removeById(id);


    }

    @Override
    public EduCourse getOver(String cId) {
        return baseMapper.getOver(cId);
    }
}




